package com.threeonemeeting.list;

import java.util.ArrayList;
import java.util.List;

import com.threeonemeeting.model.DepartmentInfo;

public class DepartmentInfoList {

	public List<DepartmentInfo> listDepartmentInfo = new ArrayList<DepartmentInfo>();

	public void addDepartmentInfo(DepartmentInfo info) {
		if (info == null)
			return;

		listDepartmentInfo.add(info);
	}

	public void addDepartmentInfo(int nId, String strDepartmentName) {
		DepartmentInfo info = new DepartmentInfo();
		info.nId = nId;
		info.strDepartmentName = strDepartmentName;
		listDepartmentInfo.add(info);
	}

	public int size() {
		return listDepartmentInfo.size();
	}

	public DepartmentInfo get(int nLocation) {
		return listDepartmentInfo.get(nLocation);
	}

	public void clear() {
		listDepartmentInfo.clear();
	}

	public DepartmentInfo getDepartmentInfo(int nId) {
		for (int i = 0; i < listDepartmentInfo.size(); i++) {
			DepartmentInfo info = listDepartmentInfo.get(i);
			if (info == null)
				continue;

			if (info.nId == nId)
				return info;
		}

		return null;
	}

	public String getDepartmentName(int nId) {
		for (int i = 0; i < listDepartmentInfo.size(); i++) {
			DepartmentInfo info = listDepartmentInfo.get(i);
			if (info == null)
				continue;

			if (info.nId == nId)
				return info.strDepartmentName;
		}

		return null;
	}

	public DepartmentInfo getDepartmentInfo(String strDepartmentName) {
		for (int i = 0; i < listDepartmentInfo.size(); i++) {
			DepartmentInfo info = listDepartmentInfo.get(i);
			if (info == null)
				continue;

			if (info.strDepartmentName.equalsIgnoreCase(strDepartmentName) == true)
				return info;
		}

		return null;
	}

	public int getDepartmentId(String strDepartmentName) {
		for (int i = 0; i < listDepartmentInfo.size(); i++) {
			DepartmentInfo info = listDepartmentInfo.get(i);
			if (info == null)
				continue;

			if (info.strDepartmentName.equalsIgnoreCase(strDepartmentName) == true)
				return info.nId;
		}

		return 0;
	}
}
